package lt.egidijus.aatest.model;

import static org.junit.Assert.*;

import java.util.ArrayList;

import junit.framework.Assert;

import lt.egidijus.aatest.generator.TestSuiteGenerator;
import lt.egidijus.aatest.junit.JUnitFinder;
import lt.egidijus.aatest.utils.Constants;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.JavaCore;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class AAtestListTest {
	
	private AAtestList testList = new AAtestList();
	ArrayList<ICompilationUnit> cList = null;
	ArrayList<ICompilationUnit> cList2 = null;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(Constants.projectName);
	JUnitFinder finder = new JUnitFinder();
	cList =  finder.findJUnitsForProject((JavaCore.create(project)));
	IProject project2 = ResourcesPlugin.getWorkspace().getRoot().getProject(Constants.testProjectName);
	cList2 =  finder.findJUnitsForProject((JavaCore.create(project2)));
	}
	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testAdd() {
		try {
			testList.add(cList.get(0));
	//		Assert.assertEquals(testList.getList().size(), 1);
		} catch (Exception e) {
			fail(e.getMessage());
		};
	}
	
	@Test
	public void testAdd2() {
		try {
			testList.add(cList2.get(1));
		//	Assert.assertEquals(testList.getList().size(), 1);
		} catch (Exception e) {
			fail(e.getMessage());
		};
	}
	
	@Test
	public void testAdd3() {
		try {
			testList.add(cList.get(1));
			testList.add(cList2.get(0));
		//	Assert.assertNotNull(testList.getList().get(0).getTestRandom());
		//	Assert.assertNotNull(testList.getList().get(0).getTestingClass());
		} catch (Exception e) {
			fail(e.getMessage());
		};
	}

	@Test
	public void testAddList() {
		try {
			testList.addList(cList);
		//	Assert.assertEquals(testList.getList().size(), 67);
		} catch (Exception e) {
			fail(e.getMessage());
		};
	}
	
	@Test
	public void testAddList2() {
		try {
			testList.addList(cList2);
		//	Assert.assertEquals(testList.getList().size(), 42);
		} catch (Exception e) {
			fail(e.getMessage());
		};
	}

	@Test
	public void testGetAATestClass() {
		try {
			testList.addList(cList);
		//	Assert.assertNotNull(testList.getAATestClass("RangeBarChart"));
		} catch (Exception e) {
			fail(e.getMessage());
		};
	}
	
	@Test
	public void testGetAATestClass2() {
		try {
			testList.addList(cList);
		//	Assert.assertNull(testList.getAATestClass("BlaBlaBla"));
		} catch (Exception e) {
			fail(e.getMessage());
		};
	}

	@Test
	public void testGetList() {
		try {
			testList.add(cList.get(0));
		//	Assert.assertEquals(testList.getList().size(), 1);
		} catch (Exception e) {
			fail(e.getMessage());
		};
	}
	
	@Test
	public void testGetList2() {
		try {
			testList.addList(cList2);
		//	Assert.assertEquals(testList.getList().size(), 40);
		} catch (Exception e) {
			fail(e.getMessage());
		};
	}

	@Test
	public void testSetList() {
		try {
//		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(Constants.projectName);
//		JUnitFinder finder = new JUnitFinder();
//		ArrayList<ICompilationUnit> cList =  finder.findJUnitsForProject((JavaCore.create(project)));
//		AAtestList listtas = new AAtestList();
//		listtas.addList(cList);
//		IProject project2 = ResourcesPlugin.getWorkspace().getRoot().getProject(Constants.testProjectName);
//		ArrayList<ICompilationUnit> cList2 =  finder.findJUnitsForProject((JavaCore.create(project2)));
//		listtas.addList(cList2);
//		ArrayList<AAtestClass> randomTests = new ArrayList<AAtestClass>();
//		for (int i = 0; i <10; i++){
//				randomTests.add(listtas.getList().get(i));
//		}
//		AAtestList testList = new AAtestList();
//		testList.setList(randomTests);
	//	Assert.assertEquals(testList.getList().size(), 10);
		} catch (Exception e) {
			fail(e.getMessage());
		};
	}

	@Test
	public void testGetTestSuiteList() {
		try {
	//		testList.addList(cList2);
	//		Assert.assertEquals(testList.getTestSuiteList().size(), 1);
		} catch (Exception e) {
			fail(e.getMessage());
		};
	}

}
